package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CarouselImage;
import com.ruoyi.system.service.ICarouselImageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 轮播图管理Controller
 *
 * @author ruoyi
 * @date 2024-03-25
 */
@RestController
@RequestMapping("/system/image")
public class CarouselImageController extends BaseController
{
    @Autowired
    private ICarouselImageService carouselImageService;

    /**
     * 查询轮播图管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:image:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody CarouselImage carouselImage)
    {
        setStartPage(carouselImage.getPageNum(),carouselImage.getPageSize());
        List<CarouselImage> list = carouselImageService.selectCarouselImageList(carouselImage);
        return getDataTable(list);
    }

    /**
     * 获取轮播图管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:image:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(carouselImageService.selectCarouselImageById(id));
    }

    /**
     * 新增轮播图管理
     */
    @PreAuthorize("@ss.hasPermi('system:image:add')")
    @Log(title = "轮播图管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody CarouselImage carouselImage)
    {
        carouselImage.setCreateBy(getUsername());
        return carouselImageService.insertCarouselImage(carouselImage);
    }

    /**
     * 修改轮播图管理
     */
    @PreAuthorize("@ss.hasPermi('system:image:edit')")
    @Log(title = "轮播图管理", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult edit(@RequestBody CarouselImage carouselImage)
    {
        return carouselImageService.updateCarouselImage(carouselImage);
    }

    /**
     * 删除轮播图管理
     */
    @PreAuthorize("@ss.hasPermi('system:image:remove')")
    @Log(title = "轮播图管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(carouselImageService.deleteCarouselImageById(id));
    }
}
